package com.woniuxy.carlife.carlifenewcomplaintsweb.controller;


import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.carlifecommonsweb.util.JwtUtil;
import com.woniuxy.carlife.carlifenewcomplaintsdomain.dto.StoreFeedbackDto;
import com.woniuxy.carlife.carlifenewcomplaintsdomain.param.StoreFeedbackParam;
import com.woniuxy.carlife.carlifenewcomplaintsweb.service.StoreFeedbackService;
import com.woniuxy.carlife.carlifenewcomplaintsweb.utils.StatusMessageEnum;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yp
 * @ClassName:StoreFeedbackController
 * @Description:门店投诉回馈
 * @date 2021/4/7 2:32
 **/
@RestController
@Slf4j
@Api(tags = "门店投诉回馈接口")
@RequestMapping("/storeFeedback")
public class StoreFeedbackController {

    @Resource
    private StoreFeedbackService storeFeedbackService;

    /*
     * 功能描述〈添加投诉回馈〉
     * @author:yp
     * @param:StoreFeedbackParam
     * @return:
     * @Date 2021/4/12 16:22
     * @throws
     */
    @PostMapping("/merchantmanage/addStoreFeedback")
    @ApiOperation(value = "添加投诉回馈信息",notes = "<span style='color:red;'>添加投诉回馈信息的接口</span>")
    @ApiResponses({
            @ApiResponse(code = 20000,message = "添加成功"),
            @ApiResponse(code=20001,message = "添加失败")
    })
    public Result addStoreFeedback(@RequestBody @ApiParam StoreFeedbackParam storeFeedbackParam){
        if(storeFeedbackParam==null){
            return new Result(false,StatusCode.ERROR,"参数错误");
        }
        log.info("开始业务:添加投诉回馈");
        int num = storeFeedbackService.addStoreFeedback(storeFeedbackParam);
        log.info("结束业务:添加投诉回馈");
        if (num==1){
            return  new Result(true, StatusCode.OK, StatusMessageEnum.SAVE_SUCCESS.toString());
        }
        return  new Result(false,StatusCode.ERROR,StatusMessageEnum.SAVE_FAIL.toString());
    }


    /*
     * 功能描述〈查询投诉回馈〉
     * @author:yp
     * @param:StoreFeedbackParam
     * @return:List<StoreFeedbackDto>
     * @Date 2021/4/12 16:42
     * @throws
     */
    @GetMapping("/ordinary/findStoreFeedback")
    @ApiOperation(value = "用户查询投诉回馈信息",notes = "<span style='color:red;'>用户查询投诉回馈信息的接口</span>")
    @ApiResponses({
            @ApiResponse(code = 20000,message = "查询成功"),
            @ApiResponse(code=20001,message = "查询失败")
    })
    public Result findStoreFeedback(){
        ServletRequestAttributes sra =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        StoreFeedbackParam storeFeedbackParam = new StoreFeedbackParam();
        storeFeedbackParam.setUserId(tokenUserId);
        log.info("开始业务:查询投诉回馈");
       List<StoreFeedbackDto> list = storeFeedbackService.findStoreFeedback(storeFeedbackParam);
        log.info("结束业务:查询投诉回馈");
        if (list.size()!=0){
            return  new Result(true, StatusCode.OK, StatusMessageEnum.FIND_SUCCESS.toString(),list);
        }
        return  new Result(false,StatusCode.ERROR,StatusMessageEnum.FIND_FAIL.toString());
    }


}

